﻿#region Copyright(C) 2013-2013 NCS Pte. Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2010 NCS Pte. Ltd. All rights reserved.
//
// SYSTEM NAME      : iConnect .Net Application Framework
// COMPONENT ID     : NCS.IConnect.Core.EntLib
// COMPONENT DESC   : Microsoft Enterprise Library Adapter.
//
// CREATED DATE/BY  : 18 Dec 2013 / Jiang Jin Nan
//
// REVISION HISTORY :
// DATE/BY            SR#/CS/PM#/OTHERS       DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Utility;
using System;
using System.Collections.Concurrent;

namespace NCS.IConnect.Core.IoC
{
    internal class DefaultInjectionExtension : UnityContainerExtension
    {
        public ConcurrentDictionary<Type, string> DefaultNames { get; private set; }
        public DefaultInjectionExtension()
        {
            this.DefaultNames = new ConcurrentDictionary<Type, string>();
        }

        public void Register(Type type, string name)
        {
            Guard.ArgumentNotNull(type, "type");
            this.DefaultNames[type] = name;
        }

        public void Register<T>(string name)
        {
            this.Register(typeof(T), name);
        }

        public bool TryGetDefaultName(Type type, out string name)
        {
            Guard.ArgumentNotNull(type, "type");
            return this.DefaultNames.TryGetValue(type, out name);
        }

        public bool TryGetDefaultName<T>(out string name)
        {
            return this.DefaultNames.TryGetValue(typeof(T), out name);
        }

        protected override void Initialize()
        {
        }
    }
}
